package cn.byapps.attendance.util;

import java.util.List;


/**
 * page 当前第几页 pagesize 每页显示记录条数 total;//总页数
 * 
 * @author Mr.chen
 *
 */
public class PageResult<T> {
	public  Pagers<T> getPageResult(List list, String page, String pagesize) {
		Pagers<T> pager = new Pagers<T>();
		if (list.size() > 0) {
			if (page == null || pagesize == null) {
				page = "1";
				pagesize = "6";
			}
			int curPage = Integer.parseInt(page);// 转换为int类型
			int pageCount = Integer.parseInt(pagesize);// 当前页数量
			int dd = list.size();
			int total = (dd + pageCount - 1) / pageCount;// 总页数

			if (curPage <= 0) {// 判断当前页数是否小于等于0，若是，则赋值1
				curPage = 1;
			}
			if (curPage > total) {// 判断当前页数是否大于总页数
				if (curPage > 0) {
					curPage = total;
				} else {
					curPage = 1;
				}
			}
			System.out.println("listres的总页数" + total + "\t当前页" + curPage + "\t当前页数量" + pageCount);
			int sindex = (curPage - 1) * pageCount;
			sindex = (sindex < list.size()) ? sindex : list.size() - 1;
			int eindex = sindex + pageCount;
			eindex = (eindex < list.size()) ? eindex : list.size();
			list = list.subList(sindex, eindex);
			/*
			 * HttpServletRequest request = ServletActionContext.getRequest();
			 * HttpSession session = request.getSession();
			 * session.setAttribute("curPage", curPage);
			 */
			pager = new Pagers<T>(list, curPage, pageCount);
		}
		return pager;

	}
	
}